package com.dexilaonian.adpter;

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.dexilaonian.R;
import com.dexilaonian.bean.HomeBean;
import com.dexilaonian.utils.Constant;
import com.dexilaonian.utils.ImageLoader;

import java.util.List;
public class GridAdapter extends BaseAdapter {

    private final Context mContext;
    private final List<HomeBean> mList_grid;

    public GridAdapter(Context context, List<HomeBean> list_grid) {
        mContext = context;
        mList_grid = list_grid;
    }

    @Override
    public int getCount() {
        return mList_grid.size();
    }

    @Override
    public Object getItem(int position) {
        return mList_grid.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(mContext);
            convertView = inflater.inflate(R.layout.province_grid_view_item_layout, null);
            holder = new ViewHolder();
            holder.ivPic = (ImageView) convertView.findViewById(R.id.iv_pic);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        String home_pic = Constant.base_pic_url + mList_grid.get(position).getPicUrl();
        ImageLoader.display(mContext,home_pic , holder.ivPic);
        return convertView;
    }

    class ViewHolder {
        ImageView ivPic;
    }
}
